
package managedbean.CRM.ProductPrice;

import entity.CRM.ProductPrice;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javaclass.ProductType;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import session.stateless.CRM.ProductPriceBeanLocal;


@ManagedBean(name="viewProductPriceManagerBean")
@ViewScoped
public class ViewProductPriceManagerBean implements Serializable{

    @EJB
    private ProductPriceBeanLocal productBeanLocal;
    private ProductPrice selectedProductPrice;
    private String statusMessage;
    
    public ViewProductPriceManagerBean() {
    }

    public ProductPrice getSelectedProductPrice() {
        return selectedProductPrice;
    }

    public void setSelectedProductPrice(ProductPrice selectedProductPrice) {
        this.selectedProductPrice = selectedProductPrice;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }
    
    public List<ProductPrice> getProductPriceList(){
        List<ProductPrice> temp=productBeanLocal.getProductPriceList();
        return productBeanLocal.getProductPriceList();
    }
    
    public void editProductPrice(ActionEvent event) throws IOException{
        selectedProductPrice = this.getSelectedProductPrice();
        if (selectedProductPrice != null){
            FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("selectedProductPrice", selectedProductPrice);            
            FacesContext.getCurrentInstance().getExternalContext().redirect("editProductPrice.xhtml");                
        }
    }
    
    public void deleteProductPrice(ActionEvent event) throws IOException
    {
        selectedProductPrice = this.getSelectedProductPrice();
        try
        {
            productBeanLocal.deleteProductPrice(selectedProductPrice.getProductPriceId()); 
            FacesContext.getCurrentInstance().getExternalContext().redirect("viewProductPrice.xhtml");
        }
        catch(Exception ex){
            ex.printStackTrace();
        }
    } 
    
    public List<ProductPrice> getProductPriceA(){
        List<ProductPrice> a_list = productBeanLocal.getProductPricesByType(ProductType.NUTS);
        return a_list;
    }
    
    public List<ProductPrice> getProductPriceB(){
        List<ProductPrice> b_list = productBeanLocal.getProductPricesByType(ProductType.FRUITS);
        return b_list;
    }
    
    public List<ProductPrice> getProductPriceC(){
        List<ProductPrice> c_list = productBeanLocal.getProductPricesByType(ProductType.CHOCOLATE_NUTS);
        return c_list;
    }
    
    public List<ProductPrice> getProductPriceD(){
        List<ProductPrice> d_list = productBeanLocal.getProductPricesByType(ProductType.REDCURRANT_FRUITS);
        return d_list;
    }
    
    
}
